import { ref } from 'vue'
import { generateRoutes } from '@/router/index'

const reportRouter = ref<any>([])
export const childrenRouter = ref<any>()
export function routeDetermination(route) {
  console.log(route)
  for (let i = 0; i < route.length; i++) {
    if (route[i].url === 'statistics/index') {
      childrenRouter.value = route[i].children
      route[i].children.forEach((res) => {
        reportRouter.value = [...new Set([...reportRouter.value, ...generateRoutes(res.children)])]
      })
      route[i].children = []
    }
  }
  return route
}

export function addChildren(route){
  for (let i = 0; i < route.length; i++) {
    if (route[i].meta.url === 'statistics/index') {
      route[i].children = reportRouter.value
    }
  }
  return route
}

